rsa key wierdness
[EroBeats.git] / Djinn and Tonic - Erobeats / visualinfo.c
blobfd27c7b3e92e5cb96ee86ee1f4a2ca5324b2eef0
1 /*
2 ** visualinfo.c
3 **
4 ** Copyright (C) Nate Robins, 1997
5 ** Michael Wimmer, 1999
6 ** Milan Ikits, 2002-2008
7 ** Nigel Stewart, 2008-2013
8 **
9 ** visualinfo is a small utility that displays all available visuals,
10 ** aka. pixelformats, in an OpenGL system along with renderer version
11 ** information. It shows a table of all the visuals that support OpenGL
12 ** along with their capabilities. The format of the table is similar to
13 ** that of glxinfo on Unix systems:
15 ** visual ~= pixel format descriptor
16 ** id = visual id (integer from 1 - max visuals)
17 ** tp = type (wn: window, pb: pbuffer, wp: window & pbuffer, bm: bitmap)
18 ** ac = acceleration (ge: generic, fu: full, no: none)
19 ** fm = format (i: integer, f: float, c: color index)
20 ** db = double buffer (y = yes)
21 ** sw = swap method (x: exchange, c: copy, u: undefined)
22 ** st = stereo (y = yes)
23 ** sz = total # bits
24 ** r = # bits of red
25 ** g = # bits of green
26 ** b = # bits of blue
27 ** a = # bits of alpha
28 ** axbf = # aux buffers
29 ** dpth = # bits of depth
30 ** stcl = # bits of stencil
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <GL/glew.h>
37 #if defined(_WIN32)
38 #include <GL/wglew.h>
39 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
40 #include <OpenGL/OpenGL.h>
41 #include <OpenGL/CGLTypes.h>
42 #elif !defined(__HAIKU__)
43 #include <GL/glxew.h>
44 #endif
46 #ifdef GLEW_MX
47 GLEWContext _glewctx;
48 # define glewGetContext() (&_glewctx)
49 # ifdef _WIN32
50 WGLEWContext _wglewctx;
51 # define wglewGetContext() (&_wglewctx)
52 # elif !defined(__APPLE__) && !defined(__HAIKU__) || defined(GLEW_APPLE_GLX)
53 GLXEWContext _glxewctx;
54 # define glxewGetContext() (&_glxewctx)
55 # endif
56 #endif /* GLEW_MX */
58 typedef struct GLContextStruct
60 #ifdef _WIN32
61 HWND wnd;
62 HDC dc;
63 HGLRC rc;
64 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
65 CGLContextObj ctx, octx;
66 #elif !defined(__HAIKU__)
67 Display* dpy;
68 XVisualInfo* vi;
69 GLXContext ctx;
70 Window wnd;
71 Colormap cmap;
72 #endif
73 } GLContext;
75 void InitContext (GLContext* ctx);
76 GLboolean CreateContext (GLContext* ctx);
77 void DestroyContext (GLContext* ctx);
78 void VisualInfo (GLContext* ctx);
79 void PrintExtensions (const char* s);
80 GLboolean ParseArgs (int argc, char** argv);
82 int showall = 0;
83 int displaystdout = 0;
84 int verbose = 0;
85 int drawableonly = 0;
87 char* display = NULL;
88 int visual = -1;
90 FILE* file = 0;
92 int
93 main (int argc, char** argv)
95 GLenum err;
96 GLContext ctx;
98 /* ---------------------------------------------------------------------- */
99 /* parse arguments */
100 if (GL_TRUE == ParseArgs(argc-1, argv+1))
102 #if defined(_WIN32)
103 fprintf(stderr, "Usage: visualinfo [-a] [-s] [-h] [-pf <id>]\n");
104 fprintf(stderr, " -a: show all visuals\n");
105 fprintf(stderr, " -s: display to stdout instead of visualinfo.txt\n");
106 fprintf(stderr, " -pf <id>: use given pixelformat\n");
107 fprintf(stderr, " -h: this screen\n");
108 #else
109 fprintf(stderr, "Usage: visualinfo [-h] [-display <display>] [-visual <id>]\n");
110 fprintf(stderr, " -h: this screen\n");
111 fprintf(stderr, " -display <display>: use given display\n");
112 fprintf(stderr, " -visual <id>: use given visual\n");
113 #endif
114 return 1;
117 /* ---------------------------------------------------------------------- */
118 /* create OpenGL rendering context */
119 InitContext(&ctx);
120 if (GL_TRUE == CreateContext(&ctx))
122 fprintf(stderr, "Error: CreateContext failed\n");
123 DestroyContext(&ctx);
124 return 1;
127 /* ---------------------------------------------------------------------- */
128 /* initialize GLEW */
129 glewExperimental = GL_TRUE;
130 #ifdef GLEW_MX
131 err = glewContextInit(glewGetContext());
132 # ifdef _WIN32
133 err = err || wglewContextInit(wglewGetContext());
134 # elif !defined(__APPLE__) && !defined(__HAIKU__) || defined(GLEW_APPLE_GLX)
135 err = err || glxewContextInit(glxewGetContext());
136 # endif
137 #else
138 err = glewInit();
139 #endif
140 if (GLEW_OK != err)
142 fprintf(stderr, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err));
143 DestroyContext(&ctx);
144 return 1;
147 /* ---------------------------------------------------------------------- */
148 /* open file */
149 #if defined(_WIN32)
150 if (!displaystdout)
152 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
153 if (fopen_s(&file, "visualinfo.txt", "w") != 0)
154 file = stdout;
155 #else
156 file = fopen("visualinfo.txt", "w");
157 #endif
159 if (file == NULL)
160 file = stdout;
161 #else
162 file = stdout;
163 #endif
165 /* ---------------------------------------------------------------------- */
166 /* output header information */
167 /* OpenGL extensions */
168 fprintf(file, "OpenGL vendor string: %s\n", glGetString(GL_VENDOR));
169 fprintf(file, "OpenGL renderer string: %s\n", glGetString(GL_RENDERER));
170 fprintf(file, "OpenGL version string: %s\n", glGetString(GL_VERSION));
171 fprintf(file, "OpenGL extensions (GL_): \n");
172 PrintExtensions((const char*)glGetString(GL_EXTENSIONS));
174 #ifndef GLEW_NO_GLU
175 /* GLU extensions */
176 fprintf(file, "GLU version string: %s\n", gluGetString(GLU_VERSION));
177 fprintf(file, "GLU extensions (GLU_): \n");
178 PrintExtensions((const char*)gluGetString(GLU_EXTENSIONS));
179 #endif
181 /* ---------------------------------------------------------------------- */
182 /* extensions string */
183 #if defined(_WIN32)
184 /* WGL extensions */
185 if (WGLEW_ARB_extensions_string || WGLEW_EXT_extensions_string)
187 fprintf(file, "WGL extensions (WGL_): \n");
188 PrintExtensions(wglGetExtensionsStringARB ?
189 (const char*)wglGetExtensionsStringARB(ctx.dc) :
190 (const char*)wglGetExtensionsStringEXT());
192 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
194 #elif defined(__HAIKU__)
196 /* TODO */
198 #else
199 /* GLX extensions */
200 fprintf(file, "GLX extensions (GLX_): \n");
201 PrintExtensions(glXQueryExtensionsString(glXGetCurrentDisplay(),
202 DefaultScreen(glXGetCurrentDisplay())));
203 #endif
205 /* ---------------------------------------------------------------------- */
206 /* enumerate all the formats */
207 VisualInfo(&ctx);
209 /* ---------------------------------------------------------------------- */
210 /* release resources */
211 DestroyContext(&ctx);
212 if (file != stdout)
213 fclose(file);
214 return 0;
217 /* do the magic to separate all extensions with comma's, except
218 for the last one that _may_ terminate in a space. */
219 void PrintExtensions (const char* s)
221 char t[80];
222 int i=0;
223 char* p=0;
225 t[79] = '\0';
226 while (*s)
228 t[i++] = *s;
229 if(*s == ' ')
231 if (*(s+1) != '\0') {
232 t[i-1] = ',';
233 t[i] = ' ';
234 p = &t[i++];
236 else /* zoinks! last one terminated in a space! */
238 t[i-1] = '\0';
241 if(i > 80 - 5)
243 *p = t[i] = '\0';
244 fprintf(file, " %s\n", t);
245 p++;
246 i = (int)strlen(p);
247 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
248 strcpy_s(t, sizeof(t), p);
249 #else
250 strcpy(t, p);
251 #endif
253 s++;
255 t[i] = '\0';
256 fprintf(file, " %s.\n", t);
259 /* ---------------------------------------------------------------------- */
261 #if defined(_WIN32)
263 void
264 VisualInfoARB (GLContext* ctx)
266 int attrib[32], value[32], n_attrib, n_pbuffer=0, n_float=0;
267 int i, pf, maxpf;
268 unsigned int c;
270 /* to get pbuffer capable pixel formats */
271 attrib[0] = WGL_DRAW_TO_PBUFFER_ARB;
272 attrib[1] = GL_TRUE;
273 attrib[2] = 0;
274 wglChoosePixelFormatARB(ctx->dc, attrib, 0, 1, &pf, &c);
275 /* query number of pixel formats */
276 attrib[0] = WGL_NUMBER_PIXEL_FORMATS_ARB;
277 wglGetPixelFormatAttribivARB(ctx->dc, 0, 0, 1, attrib, value);
278 maxpf = value[0];
279 for (i=0; i<32; i++)
280 value[i] = 0;
282 attrib[0] = WGL_SUPPORT_OPENGL_ARB;
283 attrib[1] = WGL_DRAW_TO_WINDOW_ARB;
284 attrib[2] = WGL_DRAW_TO_BITMAP_ARB;
285 attrib[3] = WGL_ACCELERATION_ARB;
286 /* WGL_NO_ACCELERATION_ARB, WGL_GENERIC_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB */
287 attrib[4] = WGL_SWAP_METHOD_ARB;
288 /* WGL_SWAP_EXCHANGE_ARB, WGL_SWAP_COPY_ARB, WGL_SWAP_UNDEFINED_ARB */
289 attrib[5] = WGL_DOUBLE_BUFFER_ARB;
290 attrib[6] = WGL_STEREO_ARB;
291 attrib[7] = WGL_PIXEL_TYPE_ARB;
292 /* WGL_TYPE_RGBA_ARB, WGL_TYPE_COLORINDEX_ARB,
293 WGL_TYPE_RGBA_FLOAT_ATI (WGL_ATI_pixel_format_float) */
294 /* Color buffer information */
295 attrib[8] = WGL_COLOR_BITS_ARB;
296 attrib[9] = WGL_RED_BITS_ARB;
297 attrib[10] = WGL_GREEN_BITS_ARB;
298 attrib[11] = WGL_BLUE_BITS_ARB;
299 attrib[12] = WGL_ALPHA_BITS_ARB;
300 /* Accumulation buffer information */
301 attrib[13] = WGL_ACCUM_BITS_ARB;
302 attrib[14] = WGL_ACCUM_RED_BITS_ARB;
303 attrib[15] = WGL_ACCUM_GREEN_BITS_ARB;
304 attrib[16] = WGL_ACCUM_BLUE_BITS_ARB;
305 attrib[17] = WGL_ACCUM_ALPHA_BITS_ARB;
306 /* Depth, stencil, and aux buffer information */
307 attrib[18] = WGL_DEPTH_BITS_ARB;
308 attrib[19] = WGL_STENCIL_BITS_ARB;
309 attrib[20] = WGL_AUX_BUFFERS_ARB;
310 /* Layer information */
311 attrib[21] = WGL_NUMBER_OVERLAYS_ARB;
312 attrib[22] = WGL_NUMBER_UNDERLAYS_ARB;
313 attrib[23] = WGL_SWAP_LAYER_BUFFERS_ARB;
314 attrib[24] = WGL_SAMPLES_ARB;
315 attrib[25] = WGL_SUPPORT_GDI_ARB;
316 n_attrib = 26;
317 if (WGLEW_ARB_pbuffer)
319 attrib[n_attrib] = WGL_DRAW_TO_PBUFFER_ARB;
320 n_pbuffer = n_attrib;
321 n_attrib++;
323 if (WGLEW_NV_float_buffer)
325 attrib[n_attrib] = WGL_FLOAT_COMPONENTS_NV;
326 n_float = n_attrib;
327 n_attrib++;
330 if (!verbose)
332 /* print table header */
333 fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
334 fprintf(file, " | | visual | color | ax dp st | accum | layer |\n");
335 fprintf(file, " | id | tp ac gd fm db sw st ms | sz r g b a | bf th cl | sz r g b a | ov un sw |\n");
336 fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
337 /* loop through all the pixel formats */
338 for(i = 1; i <= maxpf; i++)
340 wglGetPixelFormatAttribivARB(ctx->dc, i, 0, n_attrib, attrib, value);
341 /* only describe this format if it supports OpenGL */
342 if (!value[0]) continue;
343 /* by default show only fully accelerated window or pbuffer capable visuals */
344 if (!showall
345 && ((value[2] && !value[1])
346 || (!WGLEW_ARB_pbuffer || !value[n_pbuffer])
347 || (value[3] != WGL_FULL_ACCELERATION_ARB))) continue;
348 /* print out the information for this visual */
349 /* visual id */
350 fprintf(file, " |% 4d | ", i);
351 /* visual type */
352 if (value[1])
354 if (WGLEW_ARB_pbuffer && value[n_pbuffer]) fprintf(file, "wp ");
355 else fprintf(file, "wn ");
357 else
359 if (value[2]) fprintf(file, "bm ");
360 else if (WGLEW_ARB_pbuffer && value[n_pbuffer]) fprintf(file, "pb ");
362 /* acceleration */
363 fprintf(file, "%s ", value[3] == WGL_FULL_ACCELERATION_ARB ? "fu" :
364 value[3] == WGL_GENERIC_ACCELERATION_ARB ? "ge" :
365 value[3] == WGL_NO_ACCELERATION_ARB ? "no" : ". ");
366 /* gdi support */
367 fprintf(file, " %c ", value[25] ? 'y' : '.');
368 /* format */
369 if (WGLEW_NV_float_buffer && value[n_float]) fprintf(file, " f ");
370 else if (WGLEW_ATI_pixel_format_float && value[7] == WGL_TYPE_RGBA_FLOAT_ATI) fprintf(file, " f ");
371 else if (value[7] == WGL_TYPE_RGBA_ARB) fprintf(file, " i ");
372 else if (value[7] == WGL_TYPE_COLORINDEX_ARB) fprintf(file, " c ");
373 else if (value[7] == WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT) fprintf(file," p ");
374 else fprintf(file," ? ");
375 /* double buffer */
376 fprintf(file, " %c ", value[5] ? 'y' : '.');
377 /* swap method */
378 if (value[4] == WGL_SWAP_EXCHANGE_ARB) fprintf(file, " x ");
379 else if (value[4] == WGL_SWAP_COPY_ARB) fprintf(file, " c ");
380 else if (value[4] == WGL_SWAP_UNDEFINED_ARB) fprintf(file, " . ");
381 else fprintf(file, " . ");
382 /* stereo */
383 fprintf(file, " %c ", value[6] ? 'y' : '.');
384 /* multisample */
385 if (value[24] > 0)
386 fprintf(file, "%2d | ", value[24]);
387 else
388 fprintf(file, " . | ");
389 /* color size */
390 if (value[8]) fprintf(file, "%3d ", value[8]);
391 else fprintf(file, " . ");
392 /* red */
393 if (value[9]) fprintf(file, "%2d ", value[9]);
394 else fprintf(file, " . ");
395 /* green */
396 if (value[10]) fprintf(file, "%2d ", value[10]);
397 else fprintf(file, " . ");
398 /* blue */
399 if (value[11]) fprintf(file, "%2d ", value[11]);
400 else fprintf(file, " . ");
401 /* alpha */
402 if (value[12]) fprintf(file, "%2d | ", value[12]);
403 else fprintf(file, " . | ");
404 /* aux buffers */
405 if (value[20]) fprintf(file, "%2d ", value[20]);
406 else fprintf(file, " . ");
407 /* depth */
408 if (value[18]) fprintf(file, "%2d ", value[18]);
409 else fprintf(file, " . ");
410 /* stencil */
411 if (value[19]) fprintf(file, "%2d | ", value[19]);
412 else fprintf(file, " . | ");
413 /* accum size */
414 if (value[13]) fprintf(file, "%3d ", value[13]);
415 else fprintf(file, " . ");
416 /* accum red */
417 if (value[14]) fprintf(file, "%2d ", value[14]);
418 else fprintf(file, " . ");
419 /* accum green */
420 if (value[15]) fprintf(file, "%2d ", value[15]);
421 else fprintf(file, " . ");
422 /* accum blue */
423 if (value[16]) fprintf(file, "%2d ", value[16]);
424 else fprintf(file, " . ");
425 /* accum alpha */
426 if (value[17]) fprintf(file, "%2d | ", value[17]);
427 else fprintf(file, " . | ");
428 /* overlay */
429 if (value[21]) fprintf(file, "%2d ", value[21]);
430 else fprintf(file, " . ");
431 /* underlay */
432 if (value[22]) fprintf(file, "%2d ", value[22]);
433 else fprintf(file, " . ");
434 /* layer swap */
435 if (value[23]) fprintf(file, "y ");
436 else fprintf(file, " . ");
437 fprintf(file, "|\n");
439 /* print table footer */
440 fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
441 fprintf(file, " | | visual | color | ax dp st | accum | layer |\n");
442 fprintf(file, " | id | tp ac gd fm db sw st ms | sz r g b a | bf th cl | sz r g b a | ov un sw |\n");
443 fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
445 else /* verbose */
447 #if 0
448 fprintf(file, "\n");
449 /* loop through all the pixel formats */
450 for(i = 1; i <= maxpf; i++)
452 DescribePixelFormat(ctx->dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
453 /* only describe this format if it supports OpenGL */
454 if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)
455 || (drawableonly && !(pfd.dwFlags & PFD_DRAW_TO_WINDOW))) continue;
456 fprintf(file, "Visual ID: %2d depth=%d class=%s\n", i, pfd.cDepthBits,
457 pfd.cColorBits <= 8 ? "PseudoColor" : "TrueColor");
458 fprintf(file, " bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n", pfd.cColorBits, pfd.bReserved, pfd.iPixelType == PFD_TYPE_RGBA ? "rgba" : "ci", pfd.dwFlags & PFD_DOUBLEBUFFER, pfd.dwFlags & PFD_STEREO);
459 fprintf(file, " generic=%d generic accelerated=%d\n", (pfd.dwFlags & PFD_GENERIC_FORMAT) == PFD_GENERIC_FORMAT, (pfd.dwFlags & PFD_GENERIC_ACCELERATED) == PFD_GENERIC_ACCELERATED);
460 fprintf(file, " rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cRedBits, pfd.cGreenBits, pfd.cBlueBits, pfd.cAlphaBits);
461 fprintf(file, " auxBuffers=%d depthSize=%d stencilSize=%d\n", pfd.cAuxBuffers, pfd.cDepthBits, pfd.cStencilBits);
462 fprintf(file, " accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cAccumRedBits, pfd.cAccumGreenBits, pfd.cAccumBlueBits, pfd.cAccumAlphaBits);
463 fprintf(file, " multiSample=%d multisampleBuffers=%d\n", 0, 0);
464 fprintf(file, " Opaque.\n");
466 #endif
470 void
471 VisualInfoGDI (GLContext* ctx)
473 int i, maxpf;
474 PIXELFORMATDESCRIPTOR pfd;
476 /* calling DescribePixelFormat() with NULL pfd (!!!) return maximum
477 number of pixel formats */
478 maxpf = DescribePixelFormat(ctx->dc, 1, 0, NULL);
480 if (!verbose)
482 fprintf(file, "-----------------------------------------------------------------------------\n");
483 fprintf(file, " visual x bf lv rg d st ge ge r g b a ax dp st accum buffs ms \n");
484 fprintf(file, " id dep tp sp sz l ci b ro ne ac sz sz sz sz bf th cl sz r g b a ns b\n");
485 fprintf(file, "-----------------------------------------------------------------------------\n");
487 /* loop through all the pixel formats */
488 for(i = 1; i <= maxpf; i++)
490 DescribePixelFormat(ctx->dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
491 /* only describe this format if it supports OpenGL */
492 if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)
493 || (drawableonly && (pfd.dwFlags & PFD_DRAW_TO_BITMAP))) continue;
494 /* other criteria could be tested here for actual pixel format
495 choosing in an application:
497 for (...each pixel format...) {
498 if (pfd.dwFlags & PFD_SUPPORT_OPENGL &&
499 pfd.dwFlags & PFD_DOUBLEBUFFER &&
500 pfd.cDepthBits >= 24 &&
501 pfd.cColorBits >= 24)
503 goto found;
506 ... not found so exit ...
507 found:
508 ... found so use it ...
510 /* print out the information for this pixel format */
511 fprintf(file, "0x%02x ", i);
512 fprintf(file, "%3d ", pfd.cColorBits);
513 if(pfd.dwFlags & PFD_DRAW_TO_WINDOW) fprintf(file, "wn ");
514 else if(pfd.dwFlags & PFD_DRAW_TO_BITMAP) fprintf(file, "bm ");
515 else fprintf(file, "pb ");
516 /* should find transparent pixel from LAYERPLANEDESCRIPTOR */
517 fprintf(file, " . ");
518 fprintf(file, "%3d ", pfd.cColorBits);
519 /* bReserved field indicates number of over/underlays */
520 if(pfd.bReserved) fprintf(file, " %d ", pfd.bReserved);
521 else fprintf(file, " . ");
522 fprintf(file, " %c ", pfd.iPixelType == PFD_TYPE_RGBA ? 'r' : 'c');
523 fprintf(file, "%c ", pfd.dwFlags & PFD_DOUBLEBUFFER ? 'y' : '.');
524 fprintf(file, " %c ", pfd.dwFlags & PFD_STEREO ? 'y' : '.');
525 /* added: */
526 fprintf(file, " %c ", pfd.dwFlags & PFD_GENERIC_FORMAT ? 'y' : '.');
527 fprintf(file, " %c ", pfd.dwFlags & PFD_GENERIC_ACCELERATED ? 'y' : '.');
528 if(pfd.cRedBits && pfd.iPixelType == PFD_TYPE_RGBA)
529 fprintf(file, "%2d ", pfd.cRedBits);
530 else fprintf(file, " . ");
531 if(pfd.cGreenBits && pfd.iPixelType == PFD_TYPE_RGBA)
532 fprintf(file, "%2d ", pfd.cGreenBits);
533 else fprintf(file, " . ");
534 if(pfd.cBlueBits && pfd.iPixelType == PFD_TYPE_RGBA)
535 fprintf(file, "%2d ", pfd.cBlueBits);
536 else fprintf(file, " . ");
537 if(pfd.cAlphaBits && pfd.iPixelType == PFD_TYPE_RGBA)
538 fprintf(file, "%2d ", pfd.cAlphaBits);
539 else fprintf(file, " . ");
540 if(pfd.cAuxBuffers) fprintf(file, "%2d ", pfd.cAuxBuffers);
541 else fprintf(file, " . ");
542 if(pfd.cDepthBits) fprintf(file, "%2d ", pfd.cDepthBits);
543 else fprintf(file, " . ");
544 if(pfd.cStencilBits) fprintf(file, "%2d ", pfd.cStencilBits);
545 else fprintf(file, " . ");
546 if(pfd.cAccumBits) fprintf(file, "%3d ", pfd.cAccumBits);
547 else fprintf(file, " . ");
548 if(pfd.cAccumRedBits) fprintf(file, "%2d ", pfd.cAccumRedBits);
549 else fprintf(file, " . ");
550 if(pfd.cAccumGreenBits) fprintf(file, "%2d ", pfd.cAccumGreenBits);
551 else fprintf(file, " . ");
552 if(pfd.cAccumBlueBits) fprintf(file, "%2d ", pfd.cAccumBlueBits);
553 else fprintf(file, " . ");
554 if(pfd.cAccumAlphaBits) fprintf(file, "%2d ", pfd.cAccumAlphaBits);
555 else fprintf(file, " . ");
556 /* no multisample in win32 */
557 fprintf(file, " . .\n");
559 /* print table footer */
560 fprintf(file, "-----------------------------------------------------------------------------\n");
561 fprintf(file, " visual x bf lv rg d st ge ge r g b a ax dp st accum buffs ms \n");
562 fprintf(file, " id dep tp sp sz l ci b ro ne ac sz sz sz sz bf th cl sz r g b a ns b\n");
563 fprintf(file, "-----------------------------------------------------------------------------\n");
565 else /* verbose */
567 fprintf(file, "\n");
568 /* loop through all the pixel formats */
569 for(i = 1; i <= maxpf; i++)
571 DescribePixelFormat(ctx->dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
572 /* only describe this format if it supports OpenGL */
573 if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)
574 || (drawableonly && !(pfd.dwFlags & PFD_DRAW_TO_WINDOW))) continue;
575 fprintf(file, "Visual ID: %2d depth=%d class=%s\n", i, pfd.cDepthBits,
576 pfd.cColorBits <= 8 ? "PseudoColor" : "TrueColor");
577 fprintf(file, " bufferSize=%d level=%d renderType=%s doubleBuffer=%ld stereo=%ld\n", pfd.cColorBits, pfd.bReserved, pfd.iPixelType == PFD_TYPE_RGBA ? "rgba" : "ci", pfd.dwFlags & PFD_DOUBLEBUFFER, pfd.dwFlags & PFD_STEREO);
578 fprintf(file, " generic=%d generic accelerated=%d\n", (pfd.dwFlags & PFD_GENERIC_FORMAT) == PFD_GENERIC_FORMAT, (pfd.dwFlags & PFD_GENERIC_ACCELERATED) == PFD_GENERIC_ACCELERATED);
579 fprintf(file, " rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cRedBits, pfd.cGreenBits, pfd.cBlueBits, pfd.cAlphaBits);
580 fprintf(file, " auxBuffers=%d depthSize=%d stencilSize=%d\n", pfd.cAuxBuffers, pfd.cDepthBits, pfd.cStencilBits);
581 fprintf(file, " accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cAccumRedBits, pfd.cAccumGreenBits, pfd.cAccumBlueBits, pfd.cAccumAlphaBits);
582 fprintf(file, " multiSample=%d multisampleBuffers=%d\n", 0, 0);
583 fprintf(file, " Opaque.\n");
588 void
589 VisualInfo (GLContext* ctx)
591 if (WGLEW_ARB_pixel_format)
592 VisualInfoARB(ctx);
593 else
594 VisualInfoGDI(ctx);
597 /* ---------------------------------------------------------------------- */
599 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
601 void
602 VisualInfo (GLContext* __attribute__((__unused__)) ctx)
605 int attrib[] = { AGL_RGBA, AGL_NONE };
606 AGLPixelFormat pf;
607 GLint value;
608 pf = aglChoosePixelFormat(NULL, 0, attrib);
609 while (pf != NULL)
611 aglDescribePixelFormat(pf, GL_RGBA, &value);
612 fprintf(stderr, "%d\n", value);
613 pf = aglNextPixelFormat(pf);
618 /* ---------------------------------------------------------------------- */
620 #elif defined(__HAIKU__)
622 void
623 VisualInfo (GLContext* ctx)
625 /* TODO */
628 #else /* GLX */
630 void
631 VisualInfo (GLContext* ctx)
633 int n_fbc;
634 GLXFBConfig* fbc;
635 int value, ret, i;
637 fbc = glXGetFBConfigs(ctx->dpy, DefaultScreen(ctx->dpy), &n_fbc);
639 if (fbc)
641 if (!verbose)
643 /* print table header */
644 fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
645 fprintf(file, " | | visual | color | ax dp st | accum | ms | cav |\n");
646 fprintf(file, " | id | tp xr cl fm db st lv xp | sz r g b a | bf th cl | r g b a | ns b | eat |\n");
647 fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
648 /* loop through all the fbcs */
649 for (i=0; i<n_fbc; i++)
651 /* print out the information for this fbc */
652 /* visual id */
653 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_FBCONFIG_ID, &value);
654 if (ret != Success)
656 fprintf(file, "| ? |");
658 else
660 fprintf(file, " |% 4d | ", value);
662 /* visual type */
663 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_DRAWABLE_TYPE, &value);
664 if (ret != Success)
666 fprintf(file, " ? ");
668 else
670 if (value & GLX_WINDOW_BIT)
672 if (value & GLX_PBUFFER_BIT)
674 fprintf(file, "wp ");
676 else
678 fprintf(file, "wn ");
681 else
683 if (value & GLX_PBUFFER_BIT)
685 fprintf(file, "pb ");
687 else if (value & GLX_PIXMAP_BIT)
689 fprintf(file, "pm ");
691 else
693 fprintf(file, " ? ");
697 /* x renderable */
698 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_X_RENDERABLE, &value);
699 if (ret != Success)
701 fprintf(file, " ? ");
703 else
705 fprintf(file, value ? " y " : " n ");
707 /* class */
708 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_X_VISUAL_TYPE, &value);
709 if (ret != Success)
711 fprintf(file, " ? ");
713 else
715 if (GLX_TRUE_COLOR == value)
716 fprintf(file, "tc ");
717 else if (GLX_DIRECT_COLOR == value)
718 fprintf(file, "dc ");
719 else if (GLX_PSEUDO_COLOR == value)
720 fprintf(file, "pc ");
721 else if (GLX_STATIC_COLOR == value)
722 fprintf(file, "sc ");
723 else if (GLX_GRAY_SCALE == value)
724 fprintf(file, "gs ");
725 else if (GLX_STATIC_GRAY == value)
726 fprintf(file, "sg ");
727 else if (GLX_X_VISUAL_TYPE == value)
728 fprintf(file, " . ");
729 else
730 fprintf(file, " ? ");
732 /* format */
733 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_RENDER_TYPE, &value);
734 if (ret != Success)
736 fprintf(file, " ? ");
738 else
740 if (GLXEW_NV_float_buffer)
742 int ret2, value2;
743 ret2 = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_FLOAT_COMPONENTS_NV, &value2);
744 if (Success == ret2 && GL_TRUE == value2)
746 fprintf(file, " f ");
748 else if (value & GLX_RGBA_BIT)
749 fprintf(file, " i ");
750 else if (value & GLX_COLOR_INDEX_BIT)
751 fprintf(file, " c ");
752 else
753 fprintf(file, " ? ");
755 else
757 if (value & GLX_RGBA_FLOAT_ATI_BIT)
758 fprintf(file, " f ");
759 else if (value & GLX_RGBA_BIT)
760 fprintf(file, " i ");
761 else if (value & GLX_COLOR_INDEX_BIT)
762 fprintf(file, " c ");
763 else
764 fprintf(file, " ? ");
767 /* double buffer */
768 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_DOUBLEBUFFER, &value);
769 fprintf(file, " %c ", Success != ret ? '?' : (value ? 'y' : '.'));
770 /* stereo */
771 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_STEREO, &value);
772 fprintf(file, " %c ", Success != ret ? '?' : (value ? 'y' : '.'));
773 /* level */
774 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_LEVEL, &value);
775 if (Success != ret)
777 fprintf(file, " ? ");
779 else
781 fprintf(file, "%2d ", value);
783 /* transparency */
784 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_TRANSPARENT_TYPE, &value);
785 if (Success != ret)
787 fprintf(file, " ? | ");
789 else
791 if (GLX_TRANSPARENT_RGB == value)
792 fprintf(file, " r | ");
793 else if (GLX_TRANSPARENT_INDEX == value)
794 fprintf(file, " i | ");
795 else if (GLX_NONE == value)
796 fprintf(file, " . | ");
797 else
798 fprintf(file, " ? | ");
800 /* color size */
801 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_BUFFER_SIZE, &value);
802 if (Success != ret)
804 fprintf(file, " ? ");
806 else
808 if (value)
809 fprintf(file, "%3d ", value);
810 else
811 fprintf(file, " . ");
813 /* red size */
814 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_RED_SIZE, &value);
815 if (Success != ret)
817 fprintf(file, " ? ");
819 else
821 if (value)
822 fprintf(file, "%2d ", value);
823 else
824 fprintf(file, " . ");
826 /* green size */
827 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_GREEN_SIZE, &value);
828 if (Success != ret)
830 fprintf(file, " ? ");
832 else
834 if (value)
835 fprintf(file, "%2d ", value);
836 else
837 fprintf(file, " . ");
839 /* blue size */
840 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_BLUE_SIZE, &value);
841 if (Success != ret)
843 fprintf(file, " ? ");
845 else
847 if (value)
848 fprintf(file, "%2d ", value);
849 else
850 fprintf(file, " . ");
852 /* alpha size */
853 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ALPHA_SIZE, &value);
854 if (Success != ret)
856 fprintf(file, " ? | ");
858 else
860 if (value)
861 fprintf(file, "%2d | ", value);
862 else
863 fprintf(file, " . | ");
865 /* aux buffers */
866 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_AUX_BUFFERS, &value);
867 if (Success != ret)
869 fprintf(file, " ? ");
871 else
873 if (value)
874 fprintf(file, "%2d ", value);
875 else
876 fprintf(file, " . ");
878 /* depth size */
879 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_DEPTH_SIZE, &value);
880 if (Success != ret)
882 fprintf(file, " ? ");
884 else
886 if (value)
887 fprintf(file, "%2d ", value);
888 else
889 fprintf(file, " . ");
891 /* stencil size */
892 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_STENCIL_SIZE, &value);
893 if (Success != ret)
895 fprintf(file, " ? | ");
897 else
899 if (value)
900 fprintf(file, "%2d | ", value);
901 else
902 fprintf(file, " . | ");
904 /* accum red size */
905 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_RED_SIZE, &value);
906 if (Success != ret)
908 fprintf(file, " ? ");
910 else
912 if (value)
913 fprintf(file, "%2d ", value);
914 else
915 fprintf(file, " . ");
917 /* accum green size */
918 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_GREEN_SIZE, &value);
919 if (Success != ret)
921 fprintf(file, " ? ");
923 else
925 if (value)
926 fprintf(file, "%2d ", value);
927 else
928 fprintf(file, " . ");
930 /* accum blue size */
931 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_BLUE_SIZE, &value);
932 if (Success != ret)
934 fprintf(file, " ? ");
936 else
938 if (value)
939 fprintf(file, "%2d ", value);
940 else
941 fprintf(file, " . ");
943 /* accum alpha size */
944 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_ALPHA_SIZE, &value);
945 if (Success != ret)
947 fprintf(file, " ? | ");
949 else
951 if (value)
952 fprintf(file, "%2d | ", value);
953 else
954 fprintf(file, " . | ");
956 /* multisample */
957 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_SAMPLES, &value);
958 if (Success != ret)
960 fprintf(file, " ? ");
962 else
964 fprintf(file, "%2d ", value);
966 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_SAMPLE_BUFFERS, &value);
967 if (Success != ret)
969 fprintf(file, " ? | ");
971 else
973 fprintf(file, "%2d | ", value);
975 /* caveat */
976 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_CONFIG_CAVEAT, &value);
977 if (Success != ret)
979 fprintf(file, "???? |");
981 else
983 if (GLX_NONE == value)
984 fprintf(file, "none |\n");
985 else if (GLX_SLOW_CONFIG == value)
986 fprintf(file, "slow |\n");
987 else if (GLX_NON_CONFORMANT_CONFIG == value)
988 fprintf(file, "ncft |\n");
989 else
990 fprintf(file, "???? |\n");
993 /* print table footer */
994 fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
995 fprintf(file, " | id | tp xr cl fm db st lv xp | sz r g b a | bf th cl | r g b a | ns b | eat |\n");
996 fprintf(file, " | | visual | color | ax dp st | accum | ms | cav |\n");
997 fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
1002 #endif
1004 /* ------------------------------------------------------------------------ */
1006 #if defined(_WIN32)
1008 void InitContext (GLContext* ctx)
1010 ctx->wnd = NULL;
1011 ctx->dc = NULL;
1012 ctx->rc = NULL;
1015 GLboolean CreateContext (GLContext* ctx)
1017 WNDCLASS wc;
1018 PIXELFORMATDESCRIPTOR pfd;
1019 /* check for input */
1020 if (NULL == ctx) return GL_TRUE;
1021 /* register window class */
1022 ZeroMemory(&wc, sizeof(WNDCLASS));
1023 wc.hInstance = GetModuleHandle(NULL);
1024 wc.lpfnWndProc = DefWindowProc;
1025 wc.lpszClassName = "GLEW";
1026 if (0 == RegisterClass(&wc)) return GL_TRUE;
1027 /* create window */
1028 ctx->wnd = CreateWindow("GLEW", "GLEW", 0, CW_USEDEFAULT, CW_USEDEFAULT,
1029 CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL,
1030 GetModuleHandle(NULL), NULL);
1031 if (NULL == ctx->wnd) return GL_TRUE;
1032 /* get the device context */
1033 ctx->dc = GetDC(ctx->wnd);
1034 if (NULL == ctx->dc) return GL_TRUE;
1035 /* find pixel format */
1036 ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
1037 if (visual == -1) /* find default */
1039 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
1040 pfd.nVersion = 1;
1041 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
1042 visual = ChoosePixelFormat(ctx->dc, &pfd);
1043 if (0 == visual) return GL_TRUE;
1045 /* set the pixel format for the dc */
1046 if (FALSE == SetPixelFormat(ctx->dc, visual, &pfd)) return GL_TRUE;
1047 /* create rendering context */
1048 ctx->rc = wglCreateContext(ctx->dc);
1049 if (NULL == ctx->rc) return GL_TRUE;
1050 if (FALSE == wglMakeCurrent(ctx->dc, ctx->rc)) return GL_TRUE;
1051 return GL_FALSE;
1054 void DestroyContext (GLContext* ctx)
1056 if (NULL == ctx) return;
1057 if (NULL != ctx->rc) wglMakeCurrent(NULL, NULL);
1058 if (NULL != ctx->rc) wglDeleteContext(wglGetCurrentContext());
1059 if (NULL != ctx->wnd && NULL != ctx->dc) ReleaseDC(ctx->wnd, ctx->dc);
1060 if (NULL != ctx->wnd) DestroyWindow(ctx->wnd);
1061 UnregisterClass("GLEW", GetModuleHandle(NULL));
1064 /* ------------------------------------------------------------------------ */
1066 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
1068 void InitContext (GLContext* ctx)
1070 ctx->ctx = NULL;
1071 ctx->octx = NULL;
1074 GLboolean CreateContext (GLContext* ctx)
1076 CGLPixelFormatAttribute attrib[] = { kCGLPFAAccelerated, 0 };
1077 CGLPixelFormatObj pf;
1078 GLint npix;
1079 CGLError error;
1080 /* check input */
1081 if (NULL == ctx) return GL_TRUE;
1082 error = CGLChoosePixelFormat(attrib, &pf, &npix);
1083 if (error) return GL_TRUE;
1084 error = CGLCreateContext(pf, NULL, &ctx->ctx);
1085 if (error) return GL_TRUE;
1086 CGLReleasePixelFormat(pf);
1087 ctx->octx = CGLGetCurrentContext();
1088 error = CGLSetCurrentContext(ctx->ctx);
1089 if (error) return GL_TRUE;
1090 return GL_FALSE;
1093 void DestroyContext (GLContext* ctx)
1095 if (NULL == ctx) return;
1096 CGLSetCurrentContext(ctx->octx);
1097 if (NULL != ctx->ctx) CGLReleaseContext(ctx->ctx);
1100 /* ------------------------------------------------------------------------ */
1102 #elif defined(__HAIKU__)
1104 void
1105 InitContext (GLContext* ctx)
1107 /* TODO */
1110 GLboolean
1111 CreateContext (GLContext* ctx)
1113 /* TODO */
1114 return GL_FALSE;
1117 void
1118 DestroyContext (GLContext* ctx)
1120 /* TODO */
1123 /* ------------------------------------------------------------------------ */
1125 #else /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */
1127 void InitContext (GLContext* ctx)
1129 ctx->dpy = NULL;
1130 ctx->vi = NULL;
1131 ctx->ctx = NULL;
1132 ctx->wnd = 0;
1133 ctx->cmap = 0;
1136 GLboolean CreateContext (GLContext* ctx)
1138 int attrib[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None };
1139 int erb, evb;
1140 XSetWindowAttributes swa;
1141 /* check input */
1142 if (NULL == ctx) return GL_TRUE;
1143 /* open display */
1144 ctx->dpy = XOpenDisplay(display);
1145 if (NULL == ctx->dpy) return GL_TRUE;
1146 /* query for glx */
1147 if (!glXQueryExtension(ctx->dpy, &erb, &evb)) return GL_TRUE;
1148 /* choose visual */
1149 ctx->vi = glXChooseVisual(ctx->dpy, DefaultScreen(ctx->dpy), attrib);
1150 if (NULL == ctx->vi) return GL_TRUE;
1151 /* create context */
1152 ctx->ctx = glXCreateContext(ctx->dpy, ctx->vi, None, True);
1153 if (NULL == ctx->ctx) return GL_TRUE;
1154 /* create window */
1155 /*wnd = XCreateSimpleWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 1, 1, 1, 0, 0);*/
1156 ctx->cmap = XCreateColormap(ctx->dpy, RootWindow(ctx->dpy, ctx->vi->screen),
1157 ctx->vi->visual, AllocNone);
1158 swa.border_pixel = 0;
1159 swa.colormap = ctx->cmap;
1160 ctx->wnd = XCreateWindow(ctx->dpy, RootWindow(ctx->dpy, ctx->vi->screen),
1161 0, 0, 1, 1, 0, ctx->vi->depth, InputOutput, ctx->vi->visual,
1162 CWBorderPixel | CWColormap, &swa);
1163 /* make context current */
1164 if (!glXMakeCurrent(ctx->dpy, ctx->wnd, ctx->ctx)) return GL_TRUE;
1165 return GL_FALSE;
1168 void DestroyContext (GLContext* ctx)
1170 if (NULL != ctx->dpy && NULL != ctx->ctx) glXDestroyContext(ctx->dpy, ctx->ctx);
1171 if (NULL != ctx->dpy && 0 != ctx->wnd) XDestroyWindow(ctx->dpy, ctx->wnd);
1172 if (NULL != ctx->dpy && 0 != ctx->cmap) XFreeColormap(ctx->dpy, ctx->cmap);
1173 if (NULL != ctx->vi) XFree(ctx->vi);
1174 if (NULL != ctx->dpy) XCloseDisplay(ctx->dpy);
1177 #endif /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */
1179 GLboolean ParseArgs (int argc, char** argv)
1181 int p = 0;
1182 while (p < argc)
1184 #if defined(_WIN32)
1185 if (!strcmp(argv[p], "-pf") || !strcmp(argv[p], "-pixelformat"))
1187 if (++p >= argc) return GL_TRUE;
1188 display = NULL;
1189 visual = strtol(argv[p], NULL, 0);
1191 else if (!strcmp(argv[p], "-a"))
1193 showall = 1;
1195 else if (!strcmp(argv[p], "-s"))
1197 displaystdout = 1;
1199 else if (!strcmp(argv[p], "-h"))
1201 return GL_TRUE;
1203 else
1204 return GL_TRUE;
1205 #else
1206 if (!strcmp(argv[p], "-display"))
1208 if (++p >= argc) return GL_TRUE;
1209 display = argv[p];
1211 else if (!strcmp(argv[p], "-visual"))
1213 if (++p >= argc) return GL_TRUE;
1214 visual = (int)strtol(argv[p], NULL, 0);
1216 else if (!strcmp(argv[p], "-h"))
1218 return GL_TRUE;
1220 else
1221 return GL_TRUE;
1222 #endif
1223 p++;
1225 return GL_FALSE;